<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>


  <script>
    var result = [];//组合成产品集

    var selectSpec = [
      {
        name: '规格',
        items: [
          {
            id: '11',
            name: "1*1"
          }, {
            id: '22',
            name: "2*2"
          }, {
            id: '33',
            name: "3*3"
          },
        ]
      },
      {
        name: '颜色',
        items: [
          {
            id: '111',
            name: "白色"
          }, {
            id: '222',
            name: "红色"
          }, {
            id: '333',
            name: "黄色"
          },
        ]
      },
    ];


    // function combine(index, current) {
    //   if (index < selectSpec.length - 1) {
    //     var specItem = selectSpec[index];
    //     var keya = specItem.name;
    //     var items = specItem.items;
    //     if (items.length == 0) {
    //       combine(index + 1, current);
    //     }

    //     for (var i = 0; i < items.length; i++) {
    //       if (!items[i]) continue;
    //       var newMap = {};
    //       newMap = Object.assign(newMap, current);
    //       newMap[keya] = items[i];
    //       combine(index + 1, newMap);
    //     }
    //   }
    //   else if (index == selectSpec.length - 1) {
    //     var specItem = selectSpec[index];
    //     var keya = specItem.name;
    //     var items = specItem.items;
    //     if (items.length == 0) {
    //       result.push(current);
    //     }
    //     for (var i = 0; i < items.length; i++) {
    //       if (!items[i]) continue;
    //       var newMap = {};
    //       newMap = Object.assign(newMap, current);
    //       newMap[keya] = items[i];
    //       result.push(newMap);
    //     }
    //   }
    // }
    // combine(0, {});
    // console.log(result);

    function test(arr) {
      if (arr.length < 1) {
        return;
      } else if (arr.length == 1) {
        var specItem = arr[0];
        var keya = specItem.name;
        var items = specItem.items;
        if (items.length == 0) {
          return;
        }
        for (let i = 0; i < items.length; i++) {
          if (!items[i]) continue;
          var newMap = {};
          newMap = Object.assign(newMap, {});
          newMap[keya] = items[i];
          result.push(newMap);
        }
      } else {
        // arr.length >= 2
        let index = 0;
        var specItem = arr[index];
        var keya = specItem.name;
        var items = specItem.items;
        if (items.length == 0) {
          return;
        }
        for (var i = 0; i < items.length; i++) {
          if (!items[i]) continue;
          var newMap = {};
          newMap = Object.assign(newMap, current);
          newMap[keya] = items[i];
          test();
        }
      }
    }
    
    // test(selectSpec)
    console.log(result);

  </script>
</body>

</html>